<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page import ="util.MailUtility"%>
<%@include file="connection.jsp"%>

<%

            String userId = request.getParameter("user_id");
            String message = "";
            boolean mailStatus = false;
            if (userId != null) {
                Connection c = getAdminConnection();
                Statement s = c.createStatement();
                ResultSet rs = s.executeQuery("select UserID, Password, Email, Name from users where UserID='" + userId + "'");
                if (rs.first()) {
                    if (rs.getString(1).equals(userId)) {
                        try {
                            String emailContents = "Dear " + rs.getString("name") + ", \nPlease find the your password here for pms user\n\n User Id: " + userId + "\n Password: " + rs.getString("password") + " \n\n\nGood Luck\n\nPMS Password Recovery Service.";
                            mailStatus = MailUtility.sendMail(rs.getString("email"), "admin@medbill.com", emailContents, "Your MedBill Password");
                        } catch (Exception e) {
                            out.print(e);
                        }
                        if (mailStatus) {
                            message = "Password has been sent to you in the email. <a href='login.jsp'>Log in</a>";
                        } else {
                            message = "There was an error while sending you an email. <br>Check your internet connection or contact your system administrator.";
                        }
                    } else {
                        message = "User does not not exist. Pleaes enter a valid user id. <a href='forgot-password.jsp'>Try Again?</a>";
                    }
                } else {
                    message = "User does not not exist. Pleaes enter a valid user id. <a href='forgot-password.jsp'>Try Again?</a>";
                }
                rs.close();
                s.close();
                c.close();
            }

%>

<html>
    <head>
	<title>Medbill Solutions</title>
	<link href="css/medbill.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
	<table width="860" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="204" valign="top"><!-- #BeginLibraryItem "/Library/header.lbi" --><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr bgcolor="#fec707">
        <td width="36" height="204">&nbsp;</td>
        <td valign="top"><table width="191" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="49">&nbsp;</td>
          </tr>
          <tr>
            <td><a href="index.html"><img src="images/logo.gif" alt="Medbill Solutions" width="191" height="44" border="0"></a></td>
          </tr>
        </table></td>
        <td width="90" valign="top"><table width="85" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="29">&nbsp;</td>
          </tr>
          <tr>
            <td><a href="index.html">Home</a></td>
          </tr>
          <tr>
            <td height="8"></td>
          </tr>
          <tr>
            <td><a href="services.html">Services</a></td>
          </tr>
          <tr>
            <td height="8"></td>
          </tr>
          <tr>
            <td height="8"><a href="login.jsp">Log In</a></td>
          </tr>
          <tr>
            <td height="10"></td>
          </tr>
          <tr>
            <td height="16"><a href="contact.html">Contact</a></td>
          </tr>
        </table></td>
        <td width="221"><img src="images/topImage.jpg" width="221" height="204" alt="" /></td>
        <td width="93">&nbsp;</td>
      </tr>
    </table><!-- #EndLibraryItem --></td>
  </tr>
  <tr>
    <td height="30" bgcolor="#1f226f" class="headingBlue">Medical Billing and Claim Processing Professionals</td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#ccae74"><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="470" valign="top" class="txtPageTitle">Recover Password</td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="560"></td>
              </tr>
              <tr>
                <td class="txtHomeBody"></td>
              </tr>
            </table>
              <br>
        <br/>
        <br/><br/>
        <div align=center><%=message%></div>
		   <br></td>
            <td width="45" valign="top">&nbsp;</td>
            <td valign="top">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="62" valign="top"><!-- #BeginLibraryItem "/Library/footer.lbi" --><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="4" bgcolor="#c7540f"></td>
      </tr>
      <tr>
        <td height="58" bgcolor="#1e2667">&nbsp;</td>
      </tr>
    </table><!-- #EndLibraryItem --></td>
  </tr>
</table>
    </body>
</html>